package com.intellagric.controller.travel_business;

import com.intellagric.common.bean.LayuiDataGridResult;
import com.intellagric.common.bean.ResponseMessage;

import com.intellagric.interfaces.travel_business.TravelBusinessService;
import com.intellagric.pojo.TravelBusiness;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @Auther: zhy
 * @Date: 2018/10/4
 * @Description: 用户管理接口
 */
@Controller
@RequestMapping("/admin")
public class TravelBusinessController {

    @Autowired
    private TravelBusinessService travelBusinessService;


    @RequestMapping("/travelBusiness/add")
    @ResponseBody
    public ResponseMessage add(TravelBusiness travelBusiness) {
        //初始化数据
        travelBusiness.setId(UUID.randomUUID().toString().replace("-",""));

        return travelBusinessService.addTravelBusiness(travelBusiness);
    }


    @RequestMapping("/travelBusiness/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return travelBusinessService.deleteTravelBusinessById(id);
    }


    @RequestMapping("/travelBusiness/batchDelete")
    @ResponseBody
    public ResponseMessage batchDelete(@RequestParam(value="ids[]") String[] ids) {

        return travelBusinessService.batchDelete(ids);
    }



    @RequestMapping("/travelBusiness/edit")
    @ResponseBody
    public ResponseMessage edit(TravelBusiness travelBusiness) {

        return travelBusinessService.editTravelBusiness(travelBusiness);
    }


    @RequestMapping("/travelBusiness/page")
    @ResponseBody
    public LayuiDataGridResult query(int page,int limit,String keyword) {
        LayuiDataGridResult userList = travelBusinessService.getTravelBusinessList(page,limit,keyword);
        return userList;
    }

    @RequestMapping("/travelBusiness/{id}")
    @ResponseBody
    public TravelBusiness get(@PathVariable String id) {
        return travelBusinessService.getTravelBusinessById(id);
    }

    @RequestMapping("/travelBusiness/comsumption")
    @ResponseBody
    public List<Map<String, String>> comsumption(){
        return travelBusinessService.getComsumption();
    }



}
